package com.supostacks.xuetangerp.satoken;

import cn.dev33.satoken.exception.NotLoginException;
import cn.dev33.satoken.util.SaResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler
    public SaResult handleException(Exception e) {
        log.error("全局异常捕获", e);
        SaResult saResult = SaResult.error("全局异常捕获");
        if (e instanceof NotLoginException) {
            saResult.setCode(401);
            saResult.setMsg("未登录");
        }
        return saResult;
    }
}
